home *** CD-ROM | disk | FTP | other *** search
- /*
- ** BCAST.C [edit EMAIL.H before compiling]
- **
- ** This is a WIN32 console mode program that sends
- ** the same email to a list of email addresses read
- ** from a file of addresses.
- **
- ** Also see the USER example program, which verifies
- ** email receipients.
- */
-
- #include <windows.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #include "see.h"
- #include "email.h"
-
- // Email the file BCAST.MAI to each address
- // as listed in the file BCAST.EML
-
- #define EMAIL_ADDR_LIST "BCAST.EML"
- #define EMAIL_SUBJECT "Advisory"
- #define EMAIL_FILENAME "@BCAST.MAI"
-
- #define MAX_BUF 512
- static char Buffer[MAX_BUF];
-
- void ShowError(int Code)
- {seeErrorText(Code,(LPSTR)Buffer,512);
- printf("%s\n", Buffer);
- }
-
- void ErrorExit(int Code)
- {ShowError(Code);
- exit(1);
- }
-
- /* read text line (ending with LF) from disk */
-
- static int ReadTextLine(int Handle, LPSTR Buffer, int BufLen)
- {char Ch;
- int i;
- int Size = 0;
- static char TextBuffer[128];
- static int TextLeft = 0;
- static int TextRight = 0;
- while(1)
- {/* is TextBuffer[] empty ? */
- if(TextLeft>=TextRight)
- {/* read from disk */
- TextLeft = 0;
- TextRight = _lread(Handle,(LPSTR)TextBuffer,125) - 1;
- if(TextRight<0) return -1;
- }
- /* copy till LF or end of buffer */
- for(i=TextLeft;i<=TextRight;i++)
- {Ch = TextBuffer[i];
- /* throw away CRs */
- if(Ch!='\r')
- {if((Ch=='\n')||(Size==BufLen-1))
- {/* found LF or buffer is full */
- Buffer[Size] = '\0';
- TextLeft = i + 1;
- return Size;
- }
- else
- {/* save char */
- Buffer[Size++] = 0x7f & Ch;
- }
- }
- }
- /* used up all of TextBuffer[] */
- TextLeft = TextRight;
- } /* end-while */
- }
-
-
- /*** main ***/
-
- void main(void)
- {int i, n;
- int Code;
- int RcptHandle;
- static char FileName[65];
-
- /* open list of addresses file */
- RcptHandle = _lopen((LPSTR)EMAIL_ADDR_LIST,OF_READ|OF_SHARE_DENY_WRITE);
- if(RcptHandle<0)
- {printf("ERROR: Cannot open %s",EMAIL_ADDR_LIST);
- exit(1);
- }
-
- /* display parameters */
- printf("Server : %s\n",(LPSTR)SMTP_HOST_NAME);
- printf(" From : %s\n",(LPSTR)YOUR_EMAIL_ADDR);
- printf(" Subj : %s\n",(LPSTR)EMAIL_SUBJECT);
- printf(" List : %s\n",(LPSTR)EMAIL_ADDR_LIST);
- printf(" File : %s\n",(LPSTR)EMAIL_FILENAME);
-
- Code = seeVerifyFormat((LPSTR)YOUR_EMAIL_ADDR);
- if(Code<0)
- {printf("%s: ",(LPSTR)YOUR_EMAIL_ADDR );
- ErrorExit(Code);
- }
-
- /* define diagnostics log file */
- ///seeStringParam(SEE_LOG_FILE, (LPSTR)"bcast.log");
-
- printf("Connecting to %s...\n",(LPSTR)SMTP_HOST_NAME);
- Code = seeSmtpConnect(
- (LPSTR)SMTP_HOST_NAME, /* SMTP server */
- (LPSTR)YOUR_EMAIL_ADDR, /* our return email address */
- (LPSTR)NULL); /* Reply-To header */
- if(Code<0) ErrorExit(1);
-
- /* wait up to 60 seconds for server response */
- seeIntegerParam(SEE_MAX_RESPONSE_WAIT, 60000);
-
- /* read each email address in turn */
- for(i=1;;i++)
- {/* read next email destination address */
- n = ReadTextLine(RcptHandle, (LPSTR)Buffer, MAX_BUF);
- if(n<=0) break;
- /* enclose in <> brackets if necessary */
- if(strchr(Buffer,'<')) strncpy(FileName, Buffer, 64);
- else
- {/* enclose in <> brackets */
- strcpy(FileName,"<");
- strcat(FileName,Buffer);
- strcat(FileName,">");
- }
- /* check email address */
- Code = seeVerifyFormat((LPSTR)FileName);
- if(Code>=0)
- {printf("%3d: Mailing to '%s'...", i, FileName);
- /* send next email */
- Code = seeSendEmail(
- (LPSTR)FileName, /* To list */
- (LPSTR)NULL, /* CC list */
- (LPSTR)NULL, /* BCC list */
- (LPSTR)EMAIL_SUBJECT, /* subject */
- (LPSTR)EMAIL_FILENAME, /* email filename */
- (LPSTR)NULL); /* no attachment */
- if(Code>=0) printf("OK\n");
- else
- {ShowError(Code);
- seeClose();
- printf("FAILS.\n");
- /* re-connect */
- printf("Re-connecting to %s...\n",(LPSTR)SMTP_HOST_NAME);
- Code = seeSmtpConnect(
- (LPSTR)SMTP_HOST_NAME, /* SMTP server */
- (LPSTR)YOUR_EMAIL_ADDR, /* our return email address */
- (LPSTR)NULL); /* Reply-To header */
- if(Code<0) ErrorExit(1);
- }
- }
- else
- {/* display error message */
- printf("%3d: ",i);
- seeErrorText(Code,(LPSTR)Buffer,MAX_BUF);
- printf("%s in '%s'\n", Buffer, FileName);
- }
- } /* end-for */
-
- puts("All email sent.");
- _lclose(RcptHandle);
- seeClose();
- } /* end main */
-
-
-